/*
 *  $Id: AngelicSign.cs 1051 2010-05-18 22:10:41Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

namespace Ragima.Cards001.Light.Spells {
    public class AngelicSign: EnchantmentCard<ChainData> {
        public AngelicSign(): base("001_l_s_angelic_sign") {
            Level = CompleteLevel.ReadyForTest;
            Element = ElementType.Light;
            Value = 100;
            Target = new ChainTarget(null,
                new CreatureTarget(GetNewPhrase("target1"), true, false, IsHolyAndNotDisabled),
                new LandTarget(GetNewPhrase("target2"), true, true, IsNotLight));
            AddManaCost(ElementType.Light, 2);
        }

        private static bool IsHolyAndNotDisabled(TargetRequest request, Creature cr) {
            return cr.IsHoly && !cr.Disabled;
        }
        private static bool IsNotLight(TargetRequest request, Land land) {
            return land.Card.Element != ElementType.Light;
        }

        protected override void DoAction(TargetArgs<ChainData> args) {
            TargetArgs<Creature> ca;
            TargetArgs<Land> la;
            if (!args.Target.GetArgs(out ca, out la)) return;
            ca.Target.State = CreatureState.Tapped;
            la.Target.RemoveAffect<AngelicSignAffect>();
            base.DoAction(args);
        }
        protected override AbstractObject GetTarget(TargetArgs<ChainData> args) {
            TargetArgs<Land> la;
            if (!args.Target.GetArgs(1, out la)) return null;
            return la.Target;
        }
        protected override EnchantmentAffect CreateEnchantment() {
            return new AngelicSignAffect();
        }

        private class AngelicSignAffect: EnchantmentAffect<AngelicSign> {
            public AngelicSignAffect(): base(true) {
                DefaultDescription = true;
            }

            public override string DescriptionText {
                get { return Description.GetText(CasterOrOwner); }
            }

            public override void SetAffect() {
                base.SetAffect();
                CasterOrOwner.GlobalSummary.ChangeManaIncome(ElementType.Light, 1);
            }
            public override void ResetAffect() {
                base.ResetAffect();
                CasterOrOwner.GlobalSummary.ChangeManaIncome(ElementType.Light, -1);
            }

            private Player CasterOrOwner {
                get {
                    return Caster != null ? Caster : Owner.Owner;
                }
            }
        }
    }
}
